﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;

namespace ACRE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            OPT.SetString("rdb.file_lang", "English");
            OPT.SetString("db.server", "127.0.0.1");
            OPT.SetString("db.name", "Arcadia");
            OPT.SetString("db.account", "sa");
            OPT.SetString("db.password", "TLzETVhIE5s=");

            OPT.SetString("db.load_flag", "0");

            OPT.ReadOpt("ACRE.OPT");

            cbEncode.SelectedItem = OPT.GetString("rdb.file_lang");
            date_lab.Text = "";

            en_radio.Checked = true;
            en_folder_radio.Checked = true;
            ascii_checkbox.Checked = false;
        }


        private void credit_btn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Advanced Client Resource Editor v3.2", "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void open_btn_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "All Files (*.*)|*.*|RDB File (*.rdb)|*.rdb";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (!Open_RDB_Worker.IsBusy)
                {
                    Open_RDB_Worker.RunWorkerAsync();
                }
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void save_btn_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "All Files (*.*)|*.*|RDB File (*.rdb)|*.rdb";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (!Save_RDB_Worker.IsBusy)
                {
                    Save_RDB_Worker.RunWorkerAsync();
                }
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void import_rdb_btn_Click(object sender, EventArgs e)
        {
            if (!Import_RDB_DB_Worker.IsBusy)
            {
                Import_RDB_DB_Worker.RunWorkerAsync();
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void load_btn_Click(object sender, EventArgs e)
        {
            if (!Load_RDB_DB_Worker.IsBusy)
            {
                Load_RDB_DB_Worker.RunWorkerAsync();
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void search_btn_Click(object sender, EventArgs e)
        {
            RDB_Search();
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void en_radio_CheckedChanged(object sender, EventArgs e)
        {
            if (en_radio.Checked)
            {
                label1.Text = "Name: ";
                label2.Text = "Hash: ";
            }
        }

        private void de_radio_CheckedChanged(object sender, EventArgs e)
        {
            label1.Text = "Hash: ";
            label2.Text = "Name: ";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Tab_Classes.Hash.Hash_Text(en_radio, de_radio, textBox1, textBox2, name_exist, groupBox2);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void folder_dir_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                folder_dir.Text = folderBrowserDialog1.SelectedPath;
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void hash_folder_btn_Click(object sender, EventArgs e)
        {
            Tab_Classes.Hash.Hash_Folder(progressBar2, folder_dir, en_folder_radio, de_folder_radio, ascii_checkbox);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void data_dir_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                data_dir.Text = folderBrowserDialog1.SelectedPath;
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void dump_dir_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                dump_dir.Text = folderBrowserDialog1.SelectedPath;
            }
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void name_box_TextChanged(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Search(name_box, dgv3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void dump_a_Click(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Dump_All(data_dir, dump_dir, progressBar3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void dump_e_Click(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Dump_Extension(data_dir, dump_dir, ext_box, progressBar3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void dgv3_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Tab_Classes.Data_Dump.Dump_File(data_dir, dump_dir, dgv3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void db_import_Click(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Import_To_DB(progressBar3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void list_btn_Click(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Read_Type(data_dir, file_count, progressBar3, dgv3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void ext_filter_box_TextChanged(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Extension_Filter(ext_filter_box, file_count, progressBar3, dgv3);
            //Clean Memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void dgv3_SizeChanged(object sender, EventArgs e)
        {
            Tab_Classes.Data_Dump.Size_Changed(dgv3);
        }

        private void update_btn_Click(object sender, EventArgs e)
        {
        }

        private void save_update_btn_Click(object sender, EventArgs e)
        {

        }

        private void data_dir2_Click(object sender, EventArgs e)
        {
        }

        private void update_dir_Click(object sender, EventArgs e)
        {

        }

        private void dgv4_SizeChanged(object sender, EventArgs e)
        {

        }

        private void date_lab_Click(object sender, EventArgs e)
        {

        }

        private void cbSelect_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

